package com.example.testdemo.recyclerview;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.testdemo.R;

import java.util.ArrayList;
import java.util.List;

/**
 * description:
 *
 * @author zwx
 * @date 2019/8/29.
 */
public class VideoListActivity  extends AppCompatActivity {
    private List<Integer> datas;
    private VideoRecyclerView recyclerView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_list_view);
        recyclerView = findViewById(R.id.recycler_view);
        initData();

        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(new VideoListAdapter(datas, this));

    }


    private void initData(){
        datas = new ArrayList<>();
        datas.add(R.mipmap.a1);
        datas.add(R.mipmap.a2);
        datas.add(R.mipmap.a3);
        datas.add(R.mipmap.a4);
        datas.add(R.mipmap.a5);
        datas.add(R.mipmap.a6);
        datas.add(R.mipmap.a7);
        datas.add(R.mipmap.a8);
        datas.add(R.mipmap.a9);
        datas.add(R.mipmap.a10);
        datas.add(R.mipmap.b1);
        datas.add(R.mipmap.b2);
        datas.add(R.mipmap.b3);
    }
}



class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.ViewHolder>{
    private List<Integer> data;
    private Context context;
    public VideoListAdapter(List<Integer> list, Context context){
        this.context = context;
        this.data = list;
    }
    @Override
    public VideoListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_video_list_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(VideoListAdapter.ViewHolder holder, int position) {
        holder.image.setImageResource(data.get(position));
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView image;
        public ViewHolder(View itemView) {
            super(itemView);
            image = itemView.findViewById(R.id.image);
        }
    }
}
